package com.itheima.utils;

import io.jsonwebtoken.*;

import java.util.Date;
import java.util.Map;

public class JwtUtils {
    private static final String key = "itheima";
    public static String createJwt(Map<String, Object> map) {
        return Jwts.builder()
                .signWith(SignatureAlgorithm.HS256, key)
                .addClaims(map)
                .setExpiration(new Date(System.currentTimeMillis() + 1000*60*60*24))
                .compact();
    }
    public static Map<String, Object> parseJwt(String jwt) throws SignatureException, ExpiredJwtException {
        return Jwts.parser()
                .setSigningKey(key)
                .parseClaimsJws(jwt)
                .getBody();
    }
}
